/*******************************************************************************
 * Copyright (c) 2006 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.activitydiagram.tabbedproperties.section;

import org.eclipse.gef.commands.Command;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.OutputPin;
import org.eclipse.uml2.uml.ReadExtentAction;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;

import com.cea.papyrus.core.commands.factories.UMLDi2ElementDeleteFactory;
import com.cea.papyrus.core.editor.CommandStackUtils;
import com.cea.papyrus.core.filters.ClassifierFilter;
import com.cea.papyrus.core.tabbedproperties.AbstractSelectionElementSection;

/**
 * AMODIFIER................................
 */
public class ReadExtentActionClassifierSection extends AbstractSelectionElementSection{


	public ReadExtentActionClassifierSection() {
		super("Classifier: ", new ClassifierFilter());
	}
	
	@Override
	public NamedElement getReferencedElementToDisplay() {
		Classifier classifier =null;
		if( umlElement instanceof ReadExtentAction){
			classifier=((ReadExtentAction)umlElement).getClassifier();}
		return classifier;
	}

	@Override
	public void removeReferencedElement() {
		if( getElement() instanceof ReadExtentAction){
				((ReadExtentAction)getElement()).setClassifier(null);
				Command cm=UMLDi2ElementDeleteFactory.eINSTANCE.createCommand(((ReadExtentAction)getElement()).getResult());
				CommandStackUtils.getCommandStack().execute(cm);
			}
	}

	@Override
	public void setReferencedElement(NamedElement element) {
		if (element instanceof Classifier){
			Type type = (Type)element;
			OutputPin result= UMLFactory.eINSTANCE.createOutputPin();
			result.setType(type);
			result.setName(type.getName().toLowerCase());
			((ReadExtentAction)getElement()).setClassifier((Classifier)element);
			((ReadExtentAction)getElement()).setResult(result);
			result.setUpper(-1);
		}
		
	}
}